import util from '@/libs/util';
import Cookies from 'js-cookie';

export default {
    name: 'exportable-table',
    data () {
        return {
            columns: [{
                title: '学员名称',
                key: 'student_name'
            }, {
                title: '退款金额(元)',
                key: 'refund_amt',
                render:(h,params)=>{
                    return h('span',{
                        style: {
                            color:'red'
                        }
                    },"-"+params.row.refund_amt)
                }
            }, {
                title: '部门',
                key: 'department_name'
            }, {
                title: '班级名称',
                key: 'class_name'

            }, {
                title: '操作员',
                key: 'create_by'

            }, {
                title: '操作时间',
                key: 'create_time',
                render: (h, params) => {
                    return h('span', {}, util.getDate(params.row.create_time, 'time'));
                }
            },  {
                title: '操作',
                render: (h, params) => {
                    return h('Button', {
                        props: {
                            type: 'primary',
                            size: 'small'
                        },
                        style: {
                            marginRight: '5px'
                        },
                        on: {
                            click: () => {
                                console.log(params.row);
                                this.billId = params.row.bill_id;
                                this.showRefund(params.row.bill_id);
                                this.chargeDetailVisable = true;
                                this.charge_dataList=[];
                            }
                        }
                    }, '查看');
                }
            }],
            total: 0,
            pageSize: 10,
            pageIndex: 1,
            dataList: [],
            queryData: {
                studentName: '',
                startTime: '',
                endTime: ''
            },
            chargeDetailVisable:false,
            billId:'',
            orderDetails:{},
            charge_dataList: [],
            charge_columns_1: [{
                title: '项目名称',
                key: 'name'
            }, {
                title: '金额(元)',
                key: 'amt'
            },  {
                title: '打折金额',
                key: 'discountedAmt'
            }, {
                title: '打折理由'
            }],
            baseuser: JSON.parse(Cookies.get('baseUser')),
        };
    },
    mounted () {
        this.loadList();
    },
    methods: {
        loadList: function () {
            util.ajax.post('/busine/charge/refund/record/listBySql', util.toFormData({
                page: this.pageIndex,
                size: this.pageSize,
                studentName: this.queryData.studentName,
                startTime: this.queryData.startTime,
                endTime: this.queryData.endTime,
                orgId: this.baseuser.orgId
            })).then(res => {
                if(res.data.code==200){
                    this.dataList = res.data.data.list;
                    this.total = res.data.data.total;
                }
            });
        },
        showRefund:function (orderid) {
            if(typeof (orderid)=='number'){//列上的退费按钮
                util.ajax.post('/busine/charge/detailBySql', util.toFormData({
                    id: this.billId
                })).then(res => {
                    if (res.data.code == 200 && res.data.data != '') {
                        this.orderDetails = res.data.data;
                        let ord = this.orderDetails;
                        for(let i in ord.charges){
                            let charge_data={
                                'id':ord.charges[i].id,
                                'name':ord.charges[i].chargeName,
                                'amt':ord.charges[i].amt,
                                'realAmt':ord.charges[i].realAmt,
                                'discountedAmt':ord.charges[i].discountAmt,
                                'discountAmt':0,
                                'refundAmt':0,
                            }
                            this.charge_dataList.push(charge_data);
                        }
                    }
                });
            }
        },
        refresh:function () {
            this.queryData={
                studentName: '',
                startTime: '',
                endTime: ''
            }
            this.loadList();
        },
    }
};
